package com.appistry.maven.plugin.far.remote.ssh;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;

/**
 * <code>Command</code> implementation for performing secure FTP operations
 * 
 * The actual SFTP functionality is encapsulated in the <code>Sftp</code> class
 * 
 */
public class SftpCommand implements Command {

	/**
	 * Receiver/target object whose method will be called by the
	 * <code>Command</code>'s <code>execute</code> method. In this case,
	 * <code>Sftp</code> class
	 */
	private RemoteOperation sftp;

	public SftpCommand() {
		super();
	}

	public SftpCommand(RemoteOperation sftp) {
		super();
		this.sftp = sftp;
	}

	public void setRemoteOperation(RemoteOperation sftp) {
		this.sftp = sftp;
	}

	/**
	 * Calls <code>Sftp</code>'s <code>executeCommand</code> that performs the
	 * FTP operation
	 * 
	 * @throws Exception
	 */
	public void execute() throws Exception {
		try {
			sftp.run();
		} catch (JSchException jse) {
			throw jse;
		} catch (SftpException se) {
			throw se;
		}
	}

}
